﻿/*  Francis Nino Seisei 
 *  ©2012 Francis Antonio Bolaños Arias.
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Seisei.Global;
using Seisei.Nino.Generator;

namespace Seisei
{
    enum DBMS
    {
        MSSQL = 0,
        dBaseIV
    }

    enum Platform
    { 
        ADOCSharp = 0,
        ADOVBasic,
        PHPCI,
        Java
    }

    public partial class NINOAssistant : Form
    {
        public NINOAssistant()
        {
            InitializeComponent();
        }

        private void DBMSSelector_Load(object sender, EventArgs e)
        {
            cbINDBMS.SelectedIndex = 0;
        }

        private void btnListDB_Click(object sender, EventArgs e)
        {
            if (cbINDBMS.SelectedIndex == (int)DBMS.MSSQL)
            {
                Memory.Server = txtDBName.Text;
                Memory.User = txtUser.Text;
                Memory.Pass = txtPass.Text;
                cbDatabase.DataSource = MSSQL.GetDatabases();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                Memory.Server = txtDBName.Text;
                Memory.User = txtUser.Text;
                Memory.Pass = txtPass.Text;
                Memory.Database = cbDatabase.SelectedItem.ToString();

                if (rbAllTbl.Checked)
                {
                    Memory.ALL_TABLES = true;
                    Memory.INPUT_DBMS = cbINDBMS.SelectedIndex;
                    if (Memory.INPUT_DBMS == (int)DBMS.MSSQL)
                    {
                        Memory.DB_TABLES = new String[cbTable.Items.Count];
                        for (int i = 0; i < cbTable.Items.Count; i++)
                        {
                            Memory.DB_TABLES[i] = cbTable.Items[i].ToString();
                        }
                    }
                }
                else
                {
                    Memory.DB_TABLES = new string[] { cbTable.Items[cbTable.SelectedIndex].ToString() };
                    Memory.DB_TABLE_SINGLE = cbTable.Items[cbTable.SelectedIndex].ToString();
                }
                Memory.GENERATING_NINO = true;
                this.Close();
            }
            catch (NullReferenceException) {
                MessageBox.Show("Faltan datos para comenzar...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void cbDatabase_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (cbINDBMS.SelectedIndex == (int)DBMS.MSSQL)
                {
                    Memory.Server = txtDBName.Text;
                    Memory.User = txtUser.Text;
                    Memory.Pass = txtPass.Text;
                    Memory.Database = cbDatabase.SelectedItem.ToString();
                    cbTable.DataSource = MSSQL.GetTables();
                }
            }
            catch (NullReferenceException) { }
        }
    }
}
